package frame.laxcen.response;

import frame.laxcen.BaseFrame;
import frame.laxcen.exception.IllegalFrameFormatException;
import frame.laxcen.util.FrameReader;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseResponse {

    private final BaseFrame frame;

    private final Map<String, String> contentMap;

    public BaseResponse(BaseFrame baseFrame) throws IllegalFrameFormatException {

        frame = baseFrame;

        contentMap = new HashMap<>();
    }

    protected abstract Map<String, String> analyzeResponse(FrameReader reader) throws IllegalFrameFormatException;

    protected Map<String, String> explainToMap() throws IllegalFrameFormatException {

        try {

            return analyzeResponse(new FrameReader(getFrame()));

        } catch (Exception e) {

            e.printStackTrace();

            throw new IllegalFrameFormatException(e.getMessage());
        }
    }

    public Map<String, String> getContentMap() {

        return contentMap;
    }

    protected BaseFrame getFrame() {

        return frame;
    }
}
